Skip to content

feat(plugins): add GitHub Copilot (copilot-auth) built-in provider plugin - #510

Open
CharlesYWL wants to merge 2 commits into
leookun:mainfrom
CharlesYWL:charlesywl-copilot-auth-plugin
Open

CharlesYWL wants to merge 2 commits into
leookun:mainfrom
CharlesYWL:charlesywl-copilot-auth-plugin

Conversation

@CharlesYWL

Copy link
Copy Markdown

变更说明 / What

新增内置 Provider 插件 copilot-auth:用自己的 GitHub Copilot 订阅在 cursor-byok 中使用 Copilot 模型(GPT / Claude / Gemini 等)。设计文档见 copilot-auth-plugin.md。

server/plugins/build-in/copilot-auth/
├── plugin.json      清单;网络权限仅 github.com / api.github.com / 4 个 githubcopilot 域名
├── main.ts          注册 provider + github-copilot-account 资源
├── constants.ts     Client ID、版本号与请求头(身份常量集中于此)
├── oauth.ts         GitHub 设备码登录
├── token.ts         Copilot token 换取、过期前 5 分钟续期、API 域名白名单
├── resources.ts     账号存储、卡片展示(套餐 / Premium 剩余)、刷新
├── models.ts        GET /models 同步模型并按 supported_endpoints 路由
├── provider.ts      调用、重试、401 重换 token、额度冷却
├── copilot_test.ts  24 个单测
└── README.md        用法、风险声明、行为说明
server/src/plugin/builtin.rs   随二进制预装 copilot-auth
server/src/run/compaction.rs   识别 Copilot 的超长错误 model_max_prompt_tokens_exceeded,触发压缩重试

行为要点:

  • 模型列表来自账号的 /models,只保留已启用的 chat 模型;声明 /responses 的非 Anthropic 模型走 Responses API,其余走 Chat Completions,仅支持 /v1/messages 的模型暂不提供。
  • x-initiator:最后一条是用户输入时为 user,工具结果 / 助手续跑回合为 agent,不额外消耗 premium request。
  • 408 / 425 / 429 / 5xx 和边缘节点裸 403 最多重试 3 次;401 先强制重换 Copilot token 再重试一次;Premium 额度耗尽时账号冷却到重置日。
  • context 档位与其他插件一致由宿主统一提供;Copilot 返回 model_max_prompt_tokens_exceeded 时宿主现在会识别为上下文超长并压缩重试。

⚠️ 与 copilot-api 相同,插件使用 VS Code Copilot Chat 的 OAuth Client ID 和请求头,属于非官方用法,可能违反 GitHub 条款,README 中已写明风险。相关常量都集中在 constants.ts。

关联 Issue / Related Issue

无直接关联 Issue。

测试方式 / How to Test

自动化:

  • cd server/plugins/build-in/copilot-auth && deno test --allow-read(24 passed),deno check main.ts、deno fmt --check、deno lint 通过
  • cargo test -p cursor-server --lib plugin::(19 passed)、run::compaction(13 passed),cargo fmt --all -- --check 通过

手动(已在 Windows 本地 tauri build 打包安装验证前两步):

  1. 插件页 GitHub Copilot →「添加账号」→「使用 GitHub 登录」,完成设备码授权,账号卡片显示用户名、套餐与 Premium 剩余
  2. 「同步模型」,确认出现该账号可用的 Copilot 模型(实测 26 个)
  3. 在 Cursor 中分别用 GPT 系(Responses)与 Claude(Chat)模型完成对话、Agent 工具调用

仍需更多账号实测:Business / Enterprise 账号的 API 域名是否都在白名单内;子代理 / 摘要请求的 x-initiator 计费是否符合预期。

GitHub device-code login, Copilot token exchange/renewal, model sync with /responses vs /chat/completions routing, x-initiator billing, retry and premium-quota cooling. Bundled via builtin.rs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 61a7963c-8ee3-43e0-b08b-6301562403b0
GitHub Copilot rejects oversized prompts with model_max_prompt_tokens_exceeded; treat it as a context overflow so the run compacts and retries like other providers. Drop the unused contextWindow from copilot-auth model data, matching other auth plugins that leave context tiers to the host.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 61a7963c-8ee3-43e0-b08b-6301562403b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant